import React from 'react';
import { Redirect, Link } from 'umi';
import { getToken, getModuleCurrent } from '@/utils/token';
import { Result, Button } from 'antd';

const RedirectLayout = () => {
  if (getToken() === '' || getToken() === null || getToken() === 'undefined') return <Redirect to='/user/login' />;

  // 访问'/' 时，跳转系统主页   todo 
  const currentModule = getModuleCurrent();
  if (currentModule && currentModule.indexPath) {
    return <Redirect to={currentModule.indexPath} />;
  } else {
    
    return <Result
      status={403}
      title="访问失败"
      subTitle="未配置访问页面，请联系管理严."
      extra={
        <Button type="primary">
          <Link to="/user/login">重新登录</Link>
        </Button>
      }
    />;
  }
}

export default RedirectLayout;
